import { defineStore } from 'pinia'

export const useUserStore = defineStore({
  id: 'user',
  state: () => {
    return {
      token: '',
      userInfo: {},
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'xiaoluxian_user',
        storage: localStorage,
      },
    ],
  },
  actions: {
    // 设置token
    setToken(token) {
      this.token = token
    },
    // 清除token
    clearToken() {
      this.token = ''
      this.userInfo = {}
    },
  },
})
